/*
Author: Surpass-HC
Source: https://gitee.com/hxchuan000/clpc-1
Mail: surpass-hc@qq.com
*/
#ifndef __LIGHT_PROTOCOL_DIALOG_INTERFACE_H__
#define __LIGHT_PROTOCOL_DIALOG_INTERFACE_H__
#include <clptcConfig.h>
#include <systime.h>
#include <clptcFunItf.h>
typedef struct
{
    clptcFunItfStc *lpFun;
#if CLPTC_CPL_HOST_ENABLE
    sysTmTp dlgUpTmr;
    uint8_t dlgAddr;
    uint8_t dlgSmSta;   // state
    uint8_t dlgSubSta;  // sub state.
    uint8_t dlgDiscCtr; // heartbeat no response counter.
    uint8_t dlgResp;    // dialog have response.
    uint8_t dlgSn[16];
    uint8_t dlgVer[32];
#endif
    uint8_t dlgkey[16];
} clptcDlgItfStc;
int clptcDlgItfInit(clptcDlgItfStc *dlgptr, clptcFunItfStc *funptr);
int clptcDlgItfUp(clptcDlgItfStc *dlgptr);

typedef struct
{
    clptcFunItfStc *lpFunc;
    uint8_t dlgNbr; // dialog number.
    clptcDlgItfStc lpDlgs[1];
} clptcDlgMgrStc;
#define clptcDlgMgrTotalSize(dlgNbr) (offsetof(clptcDlgMgrStc, lpDlgs) + sizeof(clptcDlgItfStc) * dlgNbr)
int clptcDlgMgrInit(void *dlgMgr, clptcFunItfStc *funptr, uint8_t cfgNbr);
int clptcDlgMgrSetKey(void *dlgMgr, uint8_t cfgAddr, const uint8_t *inKey);
const uint8_t *clptcDlgMgrGetKey(void *dlgMgr, uint8_t cfgAddr);
clptcDlgItfStc *clptcDlgMgrGetDlg(void *dlgMgr, uint8_t cfgAddr);
int clptcDlgMgrUpdate(void *dlgMgr);

#if CLPTC_CPL_HOST_ENABLE
int clptcDlgStaTransfer(clptcDlgItfStc *dlgptr, uint8_t nextSta);
int clptcDlgDoCmd(clptcDlgItfStc *dlgptr, sysTmTp timeout);
int clptcDlgStaGetInf(clptcDlgItfStc *dlgptr);
int clptcDlgStaSetKey(clptcDlgItfStc *dlgptr);
int clptcDlgCmdWrtFile(clptcDlgItfStc *dlgptr, const char *optFileName, uint16_t optFileId);
void clptcDlgCmdReadFile(clptcDlgItfStc *dlgptr, const char *optFileName, uint16_t optFileId);
int clptcDlgMgrSetAddrs(void *dlgMgr, const uint8_t *inAddrs, uint8_t inAddrLen);
int clptcDlgHostUp(clptcDlgItfStc *dlgptr);
enum clptcHostDlgStaEnum
{
    clptcHostDlgSta_GetInf = 0,
    clptcHostDlgSta_SetKey,
    clptcHostDlgSta_HeartNorm,
};
#endif
#endif
